package Validaciones;
import javax.swing.*;

public class ValidacionesUsuarios {
    public static boolean validaUsuarios(String nom, JTextField text){
        if (nom.equals("") || !nom.matches("^[A-Za-zñÑ0-9]{5,10}$")) {
            pintarRojo(text);
            return true;
            
        }else{
            text.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }        
    }
    
    public static boolean validaContrasena(String pass, JTextField text){
        if (pass.equals("") || !pass.matches("^[A-Za-zñÑ0-9\\W]{5,10}$")) {
            pintarRojo(text);
            return true;
            
        }
        else if(pass.matches("^\\s+$")){
            pintarRojo(text);
            return true;
        }
        else{
            text.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 255, 0)));
            return false;
        }        
    }
    
    private static void pintarRojo(JTextField txt) {
        txt.requestFocus();
        txt.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 0, 0)));
        txt.setSelectionStart(0);
        txt.setSelectionEnd(txt.getText().length());
    }
}
